import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class SamsungTest6 {
	private static int NUM_TEST_CASE = 1;

	public static void main(String[] args) throws FileNotFoundException {
		SamsungTest6 main = new SamsungTest6();
		final long start = System.currentTimeMillis();
		Scanner scanner = new Scanner(new File("data\\samsung6.txt"));
		for (int index = 0; index < NUM_TEST_CASE; index++) {
			// Initialize
			final int SIZE = scanner.nextInt();
			char[][] src = new char[SIZE][SIZE];
			for (int i = 0; i < SIZE; i++) {
				src[i] = scanner.next().toCharArray();
			}
			// Initialize
			int sum = 0;
			for (int x = 0; x < SIZE; x++) {
				for (int y = 0; y < SIZE; y++) {
					sum += main.numberAdjacent(src, x, y, SIZE);
				}
			}
			System.out.println("Sum : " + sum);
			System.out.println("After : "
					+ (System.currentTimeMillis() - start));
		}

		scanner.close();
	}

	private int numberAdjacent(char[][] src, final int x, final int y,
			final int size) {
		if (src[x][y] != '0') {
			int temp_up = 0, temp_down = 0, temp_left = 0, temp_right = 0;
			int temp_x = x, temp_y = y;
			while (src[temp_x][temp_y--] != '0' && temp_y >= 0)
				temp_up++;
			temp_x = x;
			temp_y = y;
			while (src[temp_x][temp_y++] != '0' && temp_y < size)
				temp_down++;
			temp_x = x;
			temp_y = y;
			while (src[temp_x--][temp_y] != '0' && temp_x >= 0)
				temp_left++;
			temp_x = x;
			temp_y = y;
			while (src[temp_x++][temp_y] != '0' && temp_x < size)
				temp_right++;
			temp_x = x;
			temp_y = y;
			return Math.min(temp_up,
					Math.min(temp_down, Math.min(temp_left, temp_right)));
		}
		return 0;
	}
}
